//
//  ModulesTableViewCell.m
//  littleLight's Project-A
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 light. All rights reserved.
//

#import "ModulesTableViewCell.h"
#import "ModulesCollectionViewCell.h"
#import "ModulesModel.h"
@interface ModulesTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation ModulesTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
        
    }
    return self;
    
}


- (void)createCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 2, 220);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 240) collectionViewLayout:flowLayout];
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    self.myCollectionView.bounces = NO;
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    self.myCollectionView.showsVerticalScrollIndicator = NO;
    [self.contentView addSubview:self.myCollectionView];
    
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    
    [self.myCollectionView registerClass:[ModulesCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
    
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.myCollectionView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 240);
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ModulesCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    ModulesModel *model = [self.array objectAtIndex:indexPath.row];
    cell.model = model;
    cell.backgroundColor = [UIColor colorWithRed:251 / 255.0 green:248 / 255.0  blue:250 / 255.0 alpha:1];
    return cell;
    
}



@end
